﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model;
using System.Text;

public partial class Master_UserSiteMapPath_New : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    public Stack<PageInfo> VisitHistory
    {
        get
        {
            if (Session["PagesHistoryJJJ"] == null)
            {
                Stack<PageInfo> list = new Stack<PageInfo>();
                Session["PagesHistoryJJJ"] = list;
            }
            return Session["PagesHistoryJJJ"] as Stack<PageInfo>;
        }
        set
        {
            Session["PagesHistoryJJJ"] = value;
        }
    }

    /// <summary>
    /// 删除最后访问链接
    /// </summary>
    /// <param name="pageinfo"></param>
    public void ModifyLastLink()
    {
        Stack<PageInfo> list = VisitHistory;
        if (VisitHistory.Count > 0)
        {
            list.Pop();
        }
        VisitHistory = list;
    }
    /// <summary>
    /// 增加访问链接
    /// </summary>
    /// <param name="pageinfo"></param>
    public void AddLink(PageInfo pageinfo)
    {
        if (pageinfo.Title == "企业汇总统计")
        {
            Stack<PageInfo> list = VisitHistory;
            list.Clear();
            list.Push(pageinfo);
            VisitHistory = list;
        }
        else
        {
            Stack<PageInfo> list = VisitHistory;
            list.Push(pageinfo);
            VisitHistory = list;
        }
        
    }

    /// <summary>
    /// 清空链接列表
    /// </summary>
    public void ClearLink()
    {
        Stack<PageInfo> list = VisitHistory;
        list.Clear();
        VisitHistory = list;
    }

    public string GetText()
    {
        bool first = true;
        StringBuilder sb = new StringBuilder();
        Stack<PageInfo> VisitHistoryShow = new Stack<PageInfo>(VisitHistory.ToArray());

        foreach (var item in VisitHistoryShow)
        {
            if (first)
            {
                sb.AppendFormat("您的位置：<a href='{1}'>{0}</a>", item.Title, item.URL);
                first = false;
            }
            else
            {
                sb.AppendFormat(" » <a href='{1}'>{0}</a>", item.Title, item.URL);
            }
        }
        //追加 “查询提示条件”
        SuperviseQuery query =  URLUtil.GetSuperviseQueryFromURL(Request);
        if (query == null)
        {
            query = new SuperviseQuery();
        }
        if (!string.IsNullOrEmpty( query._QueryPrompt) )
        {
            sb.Append(" " + query._QueryPrompt);
        }
        return sb.ToString();
    }


    public void SetText()
    {
        ltlNav.Text = GetText();
    }


    public void GetHistoryPages()
    {
        //foreach (LinkPageInfo objclsLinkPageInfo in LinkPageInfolist)
        //{
        //    LinkButton lbtn = new LinkButton();
        //    lbtn.Text = objclsLinkPageInfo.Title;
        //    lbtn.ID = objclsLinkPageInfo.SessionID;
        //    lbtn.PostBackUrl = string.Format("{0}?sessionid={1}",objclsLinkPageInfo.URL,objclsLinkPageInfo.SessionID);

        //    this.PlaceHolder1.Controls.Add(lbtn); 

        //}

        //PageHistory ph = (PageHistory)Session[PageHistory.SessionName];
        //if (ph == null)
        //    ph = new PageHistory();

        //List<LinkPageInfo> LinkPageInfolist = ph.HistoryLinkPages;
        //for (int i = 0; i < LinkPageInfolist.Count; i++)
        //{
        //    LinkButton lbtn = new LinkButton();
        //    lbtn.Text = LinkPageInfolist[i].Title + "   ";
        //    lbtn.ID = LinkPageInfolist[i].SessionID;
        //    lbtn.PostBackUrl = string.Format("{0}?sessionid={1}", LinkPageInfolist[i].URL, LinkPageInfolist[i].SessionID);
        //    lbtn.CommandName = i.ToString();
        //    lbtn.Click += new System.EventHandler(lbtn_Click);
        //    this.PlaceHolder1.Controls.Add(lbtn);
        //}

    }

    private void lbtn_Click(object sender, EventArgs e)
    {
        //throw new NotImplementedException();

        // LinkButton lbtn = ((LinkButton)sender);

        //退回到某一个页面，把list修改
        //PageHistory ph = (PageHistory)Session[PageHistory.SessionName];
        //ph.BackPage(int.Parse(lbtn.CommandName.ToString()));
        //Session[PageHistory.SessionName] = ph;
        //Response.Redirect(lbtn.PostBackUrl);

    }




    //public void GetHistoryPages()
    //{
    //    for (int i = 0; i < 5; i++)
    //    {
    //        LinkButton lbtn = new LinkButton();
    //        lbtn.Text = i + "按企业查看" +"-->";
    //        lbtn.ID = i.ToString();
    //        this.PlaceHolder1.Controls.Add(lbtn);
    //    }
    //}
    //protected void lbtn_Click(object sender, EventArgs e)
    //{

    //}
}
